# encoding: utf-8
# @Author: zsl
# @Time  : 2024/10/20 22:13
# @Desc :如果不确定该使用del语句还是pop()方法，下面是一个简单的判断标准：如
# 果要从列表中删除一个元素，且不再以任何方式使用它，就使用del语句；
# 如果要在删除元素后继续使用它，就使用pop()方法。

# 修改列表元素
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)

motorcycles[0] = 'ducati'
print(motorcycles)

# 在列表末尾添加元素
motorcycles.append('ducati')
print(motorcycles)

motorcycles = []
motorcycles.append('honda')
motorcycles.append('yamaha')
motorcycles.append('suzuki')
print(motorcycles)

# 在列表中插入元素
# motorcycles.insert(0,'ducati')
# print(motorcycles)

# 使用del语句删除元素
# del motorcycles[0]
# print(motorcycles)

# del motorcycles[1]
# print(motorcycles)

# 使用pop()方法删除元素
# popped_motorcycle=motorcycles.pop()
# print(motorcycles)
# print(f"The last motorcycle I owned was a {popped_motorcycle.title()}.")

# 删除列表中任意位置的元素
# first_owned=motorcycles.pop(0)
# print(f"The first motorcycle I owned was a {first_owned.title()}.")

# 根据值删除元素
too_expensive="honda"
motorcycles.remove(too_expensive)
print(motorcycles)
print(f"\nA {too_expensive.title()} is too expensive for me.")

